package com.jwell.panrank.ui.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.AppCompatSpinner
import android.support.v7.widget.LinearLayoutManager
import android.text.TextUtils
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import com.jwell.cargoapp.ui.base.MVPBaseActivity
import com.jwell.panrank.R
import com.jwell.panrank.application.App
import com.jwell.panrank.contract.PreRegisterPlaneContract
import com.jwell.panrank.entity.InlineBean
import com.jwell.panrank.entity.ReleaseCodeBean
import com.jwell.panrank.model.PreRegisterPlaneModel
import com.jwell.panrank.presenter.PreRegisterPlanePresenter
import com.jwell.panrank.tools.RecyclerViewDivider
import com.jwell.panrank.ui.adapter.RegisterPlaneAdapter
import com.jwell.panrank.ui.custom.CustomEditText
import com.jwell.panrank.ui.custom.DateChooseWheelViewDialog
import com.jwell.panrank.ui.dialog.ChooseStringDialog
import com.jwell.panrank.ui.dialog.PreRegisterPlaneDialog
import kotlinx.android.synthetic.main.activity_pre_register_plane.*
import kotlinx.android.synthetic.main.pre_register_plane_step1_layout.*
import kotlinx.android.synthetic.main.pre_register_plane_step2_layout.*
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import kotlin.concurrent.timerTask

/**
 * 预登记验收计划
 */
class PreRegisterPlaneActivity : MVPBaseActivity<PreRegisterPlanePresenter>(), PreRegisterPlaneContract.View, View.OnClickListener {

    private var list = ArrayList<InlineBean>()
    private var mReleaseArray = ArrayList<ReleaseCodeBean>()
    private var adapter = RegisterPlaneAdapter(list)
    //控制步骤
    private var step = 1
    //选择物资名称
    private val CHOOSE_GOODS_NAME = 0
    //如果收货单位是球团厂，计量单位有标证除皮，否则没有
    private var isOutOfSkin = false
    //选择发货单位
    private val CHOOSE_SEND_COM_NAME = 1
    //选择收货单位
    private val CHOOSE_RECEPT_COM_NAME = 2
    //选择合同号
    private val CHOOSE_CONTRACH = 4
    private var startTime: String? = null
    private var endTime: String? = null
    //供量计划开始时间
    private var date1: Date? = null
    //供量计划结束时间
    private var date2: Date? = null
    //当前时间，供量计划开始时间必须从明天开始
    private var date3: Date? = null
    //货物代码
    private var orG_CODE: String? = null
    private var mLastReleaseTime: Int = -1 //上一个放号时间
    private var mLastReleaseNum: Int = -1//上一个放号车数
    override fun createPresenter(): PreRegisterPlanePresenter? {
        return PreRegisterPlanePresenter()
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pre_register_plane)
        initToolBar("收料计划", true, null)
        setListener()
        setLabelSelected(true, false)
        setLabelSelected1(true, false)
        step2_recyclerView.adapter = adapter
        step2_recyclerView.layoutManager = LinearLayoutManager(this)
        step2_recyclerView.addItemDecoration(RecyclerViewDivider(this, LinearLayoutManager.VERTICAL, resources.getDimensionPixelSize(R.dimen.dp_7), resources.getColor(R.color.background)))
    }

    private fun setListener() {
        ll_btn1.setOnClickListener(this)
        ll_btn2.setOnClickListener(this)
        rl_item11.setOnClickListener(this)
        rl_item12.setOnClickListener(this)
        rl_item21.setOnClickListener(this)
        rl_item22.setOnClickListener(this)
        rl_item23.setOnClickListener(this)
        step2_text_delete.setOnClickListener(this)
//        text_sendCom.setOnClickListener(this)
//        text_receiptCom.setOnClickListener(this)
        text_goodsName.setOnClickListener(this)
        btn_chooseContract.setOnClickListener(this)
        text_chooseStartTime.setOnClickListener(this)
        text_chooseEndTime.setOnClickListener(this)
        text_release_days.setOnClickListener(this)
        ll_add_view.setOnClickListener(this)
        radio_group_relase.setOnCheckedChangeListener { group, checkedId ->
            when (checkedId) {
                R.id.arb_release_yes -> {
                    ll_add_root.visibility = View.VISIBLE
                }
                R.id.arb_release_no -> {
                    ll_add_root.visibility = View.GONE
                }
            }
        }
    }

    override fun onClick(v: View?) {
        var bundle = Bundle()
        when (v?.id) {
            R.id.text_release_days -> {
                val stringList = mutableListOf<String>("1天", "2天", "3天", "5天", "7天")
                var dialog1 = ChooseStringDialog.Builder(this, stringList)
                        .setOnclickListener { days ->
                            val day = when (days) {
                                "1天" -> 1
                                "2天" -> 2
                                "3天" -> 3
                                "5天" -> 5
                                "7天" -> 7
                                else -> 0
                            }
                            text_release_days.text = day.toString()
                        }
                        .creat()
                dialog1.show()
            }

            R.id.text_chooseStartTime -> {//选择开始时间
                val startDateChooseDialog = DateChooseWheelViewDialog(this@PreRegisterPlaneActivity, DateChooseWheelViewDialog.DateChooseInterface { time, longTimeChecked ->
                    text_chooseStartTime.text = time
                    startTime = time
                    checkTime()
                })
                startDateChooseDialog.setDateDialogTitle("供量开始时间")
                startDateChooseDialog.setTimePickerGone(true)
                startDateChooseDialog.showDateChooseDialog()
            }
            R.id.text_chooseEndTime -> {//选择结束时间
                val startDateChooseDialog = DateChooseWheelViewDialog(this@PreRegisterPlaneActivity, DateChooseWheelViewDialog.DateChooseInterface { time, longTimeChecked ->
                    text_chooseEndTime.text = time
                    endTime = time
                    checkTime()

                })
                startDateChooseDialog.setDateDialogTitle("供量结束时间")
                startDateChooseDialog.setTimePickerGone(true)
                startDateChooseDialog.showDateChooseDialog()

            }
            R.id.step2_text_delete -> {
                adapter.setCheckBox(true)
                text_btn1.text = "取消"
                text_btn2.text = "确定删除"
            }
            R.id.ll_btn1 -> {
                when (text_btn1.text) {
                    "下一步" -> {
//                        if (text_sendCom.text.isNullOrEmpty()) {
//                            toast("请选择或输入发货单位")
//                            return
//                        }
//                        if (text_receiptCom.text.isNullOrEmpty()) {
//                            toast("请选择或输入收货单位")
//                            return
//                        }
                        if (text_label11.isSelected && text_goodsName.text.isNullOrEmpty()) {
                            toast("请选择物资名称")
                            return
                        }
                        if (text_chooseStartTime.text.isNullOrEmpty()) {
                            toast("请选择供量开始时间")
                            return
                        }
                        //检测选择时间是否正确,供量开始时间不能晚于明日
                        if (!checkTime()) {
                            return
                        }
                        when (ll_release_days.visibility) {
                            View.VISIBLE -> {
                                if (text_release_days.text.isNullOrEmpty()) {
                                    toast("请选提前发布天数")
                                    return
                                }
                            }
                        }
                        //收集放号的数据
                        if (collectReleaseData()) {
                            Log.d("ds", "collectReleaseData-2还有数据没填")
                            return
                        }

                        step++
                        setDataCausedStep()
                    }
                    "上一步" -> {
                        step--
                        setDataCausedStep()
                    }
                    "取消" -> {
                        for (item in list) {
                            item.checked = false
                        }
                        adapter.setCheckBox(false)
                        when (step) {
                            1 -> text_btn1.text = "下一步"
                            2 -> text_btn1.text = "上一步"
                        }
                        text_btn2.text = "发布计划"
                    }
                }
            }
            R.id.ll_btn2 -> {
                when (text_btn2.text) {
                    "确定删除" -> {
                        list.filter { it.checked }.forEach { list.remove(it) }
                        adapter.setCheckBox(false)
                        //删除所选选项
                        text_btn2.text = "发布计划"
                        text_btn1.text = "上一步"
                    }
                    "发布计划" -> {
                        //检测调度司机是否正确
                        if (!checkDispatchInfo()) {
                            return
                        }
                        var requestData = PreRegisterPlaneModel.RequestData()
                        var dispatchInfoList = ArrayList<PreRegisterPlaneModel.DispatchInfo>()
                        for (item in list) {
                            var dispatchInfo = PreRegisterPlaneModel.DispatchInfo()
                            dispatchInfo.appointCarCount = item.carNum
                            dispatchInfo.mtrlOrderNo = item.mtrL_ORDER_NO
                            dispatchInfo.mtrlDescr = item.mtrL_DESCR
                            dispatchInfo.materialCode = item.mtrL_NAME
                            dispatchInfo.supplierName = item.supplieR_NAME
                            dispatchInfo.supplierId = item.supplieR_ID
                            dispatchInfo.isRobbing = item.isRobbing
                            dispatchInfo.id = item.id
                            dispatchInfoList.add(dispatchInfo)
                        }
                        if (rl_item11.isSelected) {//按品种名
                            requestData.planType = 2
                        } else if (rl_item12.isSelected) {//按合同号
                            requestData.planType = 1
                        }
                        if (rl_item21.isSelected) {//计量方式，先重后空
                            requestData.measurementMethod = 1
                        } else if (rl_item22.isSelected) {//计量方式，标证除皮
                            requestData.measurementMethod = 3
                        }
                        //计划车数
                        if (text_carNum.text.isNullOrEmpty()) {
                            requestData.planCarCount = null
                        } else {
                            requestData.planCarCount = text_carNum.text.toString().toInt()
                        }
                        //物资名称
                        if (text_goodsName.text.isNullOrEmpty()) {
                            requestData.materialName = null
                        } else {
                            requestData.materialName = text_goodsName.text.toString()
                        }
                        requestData.materialCode = orG_CODE
//                        //发货单位
//                        requestData.forwardingUnit = text_sendCom.text.toString()
//                        //收货单位
//                        requestData.receivingUnit = text_receiptCom.text.toString()
                        //供应开始时间
                        requestData.planDate = text_chooseStartTime.text.toString()
                        //供应结束时间
                        requestData.planDateEnd = text_chooseEndTime.text.toString()
                        when (ll_release_days.visibility) {
                            View.VISIBLE -> {
                                //提前发布天数
                                requestData.advanceDay = text_release_days.text.toString().toInt()
                            }
                        }
                        requestData.fixedPointList = mReleaseArray
                        requestData.isFixedPoint = radio_group_relase.checkedRadioButtonId == R.id.arb_release_yes
                        requestData.fuelPlanDetail = dispatchInfoList
                        requestData.id = null

                        PreRegisterPlaneDialog.Builder(this, requestData)
                                .setSureOnclickListener(object : PreRegisterPlaneDialog.SusreOnclickListener {
                                    override fun onClick() {
                                        showProgress("", true)
                                        presenter?.createFuelPlan(requestData)
                                    }
                                }).create().show()
                    }
                }
            }
            R.id.btn_chooseContract -> {//选择合同号
                val intent = Intent(this, SearchActivity::class.java)
                bundle.putInt("type", CHOOSE_CONTRACH)
                bundle.putBoolean("canInput", false)
                intent.putExtras(bundle)
                startActivityForResult(intent, CHOOSE_CONTRACH)
            }
            R.id.text_goodsName -> {
                val intent = Intent(this, SearchActivity::class.java)
                bundle.putInt("type", CHOOSE_GOODS_NAME)
                bundle.putInt("goodsType", 1)
                bundle.putBoolean("canInput", false)
                intent.putExtras(bundle)
                startActivityForResult(intent, CHOOSE_GOODS_NAME)
            }
            R.id.text_sendCom -> {
//                val intent = Intent(this, SearchActivity::class.java)
//                bundle.putInt("type", CHOOSE_SEND_COM_NAME)
//                bundle.putBoolean("canInput", "按单位名称/编码搜索或直接输入" == text_sendCom.hint)
//                intent.putExtras(bundle)
//                startActivityForResult(intent, CHOOSE_SEND_COM_NAME)
            }
            R.id.text_receiptCom -> {
//                val intent = Intent(this, SearchActivity::class.java)
//                bundle.putInt("type", CHOOSE_RECEPT_COM_NAME)
//                bundle.putBoolean("canInput", "按单位名称/编码搜索或直接输入" == text_receiptCom.hint)
//                intent.putExtras(bundle)
//                startActivityForResult(intent, CHOOSE_RECEPT_COM_NAME)
            }
            R.id.rl_item11 -> {
                setLabelSelected(true, false)
            }
            R.id.rl_item12 -> {
                setLabelSelected(false, true)
            }
            R.id.rl_item21 -> {
                setLabelSelected1(true, false)
            }
            R.id.rl_item22 -> {
                setLabelSelected1(false, true)
            }
            R.id.rl_item23 -> {
                setLabelSelected1(false, false)
            }

            R.id.ll_add_view -> {
                addChildView()
            }
        }
    }

    private fun addChildView() {
        var childView: View = LayoutInflater.from(this).inflate(R.layout.layout_pre_release_number, null)
        var imageView: ImageView = childView.findViewById(R.id.iv_close)
        imageView.visibility = View.VISIBLE
        imageView.setOnClickListener {
            ll_add_root.removeView(childView)
            if (ll_add_root.childCount - 1 >= 24) {
                ll_add_view.visibility = View.GONE
            } else {
                ll_add_view.visibility = View.VISIBLE
            }
        }

        ll_add_root.addView(childView, if (ll_add_root.childCount - 2 < 0) 0 else ll_add_root.childCount - 1)
        if (ll_add_root.childCount - 1 >= 24) {
            ll_add_view.visibility = View.GONE
        } else {
            ll_add_view.visibility = View.VISIBLE
        }
    }

    private fun collectReleaseData(): Boolean {
        when (radio_group_relase.checkedRadioButtonId) {
            R.id.arb_release_yes -> {
                mReleaseArray.clear()
                mLastReleaseNum = -1
                mLastReleaseTime = -1
                var childCount = ll_add_root.childCount - 1
                Log.d("", "collectReleaseData-0-$childCount")
                for (i in 0..(childCount - 1)) {
                    Log.d("", "collectReleaseData-0-$i")
                    var childView: View = ll_add_root.getChildAt(i) ?: break
                    var appCompatSpinner: AppCompatSpinner? = childView.findViewById(R.id.acspiner_release_time)
                    var customEditText: CustomEditText? = childView.findViewById(R.id.cet_release_number)

                    if (appCompatSpinner == null) {
                        return true
                    }
                    //检查时间
                    if (appCompatSpinner.selectedItemPosition <= mLastReleaseTime) {
                        toast("每一次选的时间应大于上次放号时间！")
                        return true;
                    }
                    mLastReleaseTime = appCompatSpinner.selectedItemPosition

                    if (TextUtils.isEmpty(customEditText?.text.toString())) {
                        toast("请填写放号车数！")
                        return true;
                    }
//                    检查车数
                    if (Integer.valueOf(customEditText?.text.toString()) <= 0) {
                        toast("车数应该大于0！")
                        return true;
                    }
                    if (!text_carNum.text.isNullOrEmpty()&&Integer.valueOf(customEditText?.text.toString())>Integer.valueOf(text_carNum?.text.toString())) {
                        toast("车数不能大于计划车数！")
                        return true;
                    }
                    if (Integer.valueOf(customEditText?.text.toString()) <= mLastReleaseNum) {
                        toast("车数应该大于上一次放号车数！")
                        return true;
                    }
                    mLastReleaseNum = Integer.valueOf(customEditText?.text.toString())

                    var bean = ReleaseCodeBean(appCompatSpinner?.selectedItemPosition, customEditText?.text.toString())
                    mReleaseArray.add(bean)
                }
                return false
            }
            R.id.arb_release_no -> {
            }
        }
        return false;
    }

    //检测调度信息是否正确
    private fun checkDispatchInfo(): Boolean {
        //总调度车数
        var totalNum = 0
        if (list.isEmpty()) {
            toast("请至选择一个合同号")
            return false
        }
        for (item in list) {
            if (item.carNum > 0) {
                totalNum += item.carNum
            }
//            else {
//                toast("请完善调度信息")
//                return false
//            }
        }
        if (!text_carNum.text.isNullOrEmpty()) {
            var carNum = text_carNum.text.toString().toInt()
            if (carNum < totalNum) {
                toast("指定供应车数之和不能大于计划车数")
                return false
            }
        }
        return true
    }

    //检测所选时间是否正确
    private fun checkTime(): Boolean {
        val calendar = Calendar.getInstance()
        val nowYEAR = calendar.get(Calendar.YEAR)
        val nowMONTH = calendar.get(Calendar.MONTH) + 1
        val nowDATE = calendar.get(Calendar.DATE)
        val nowTime = nowYEAR.toString() + "-" + nowMONTH.toString() + "-" + nowDATE
        val format = SimpleDateFormat("yyyy-MM-dd")
        try {
            date1 = format.parseObject(startTime) as Date
            date3 = format.parseObject(nowTime) as Date
        } catch (e: Exception) {
            e.printStackTrace()
        }
//        if (date1 == date3) {
//            toast("开始时间不能晚于明日!")
//            return false
//        }
        try {
            when (date3?.after(date1)) {
                true -> {
                    toast("开始时间不能晚于今日!")
                    return false
                }
            }
            endTime?.let {
                try {
                    date2 = format.parseObject(endTime) as Date
                    if (date1 == date2) {
                        endTime = null
                    }
                } catch (e: ParseException) {

                }
                when (date1?.after(date2)) {
                    true -> {
                        toast("结束时间不能晚于开始时间")
                        ll_release_days.visibility = View.GONE
                        return false
                    }
                    else -> {
                        if (date1 == date2) {
                            ll_release_days.visibility = View.GONE
                            text_release_days.text = ""
                        } else {
                            ll_release_days.visibility = View.VISIBLE
                        }
                    }
                }
            }
        } catch (e: Exception) {
            return false
        }
        return true
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        when (resultCode) {
            Activity.RESULT_OK -> {
                when (requestCode) {
                    CHOOSE_GOODS_NAME -> {
                        text_goodsName.text = data?.getStringExtra("input")
                        orG_CODE = data?.getStringExtra("orG_CODE")
                        orG_CODE?.let {
                            presenter?.getContractListByProName(it)
                        }
                        setLabelSelected1(true, false)
                    }
                    CHOOSE_SEND_COM_NAME -> {
//                        text_sendCom.text = data?.getStringExtra("input")
                    }
                    CHOOSE_RECEPT_COM_NAME -> {
//                        text_receiptCom.text = data?.getStringExtra("input")
//                        isOutOfSkin = text_receiptCom.text == "钢企球团厂"
//                        setLabelSelected1(true, false)
                    }
                    CHOOSE_CONTRACH -> {
                        var checkedInLineList = ArrayList<InlineBean>()
                        data?.extras?.get("selectedInLineList")?.let {
                            checkedInLineList = it as ArrayList<InlineBean>
                        }
                        Log.i("TAG", "checkedInLineList" + checkedInLineList.size)
                        if (list.isEmpty()) {
                            list.addAll(checkedInLineList)
                        } else {
                            //去除重复添加的选项
                            for (item in checkedInLineList) {
                                list
                                        .filter { it.guid == item.guid }
                                        .forEach { item.isAdded = true }
                            }
                            checkedInLineList
                                    .filterNot { it.isAdded }
                                    .forEach { list.add(it) }
                        }
                        adapter.notifyDataSetChanged()
                    }
                }
            }
        }
    }

    //选择计量类别
    private fun setLabelSelected(c1: Boolean, c2: Boolean) {
        rl_item11.isSelected = c1
        rl_item12.isSelected = c2
        list.clear()
        setTextColor(c1, text_label11, image_tick_11)
        setTextColor(c2, text_label12, image_tick_12)
        if (c1) {//按品种名发布，需要选择货物名称
            ll_goodsName.visibility = View.VISIBLE
            ll_chooseCompact.visibility = View.GONE
        }
        if (c2) {//按合同号发布，不需要选择货物名称
            ll_goodsName.visibility = View.GONE
            text_goodsName.text = null
            ll_chooseCompact.visibility = View.VISIBLE
        }
    }

    //设置计量方式选中项
    private fun setLabelSelected1(c1: Boolean, c2: Boolean) {
        //球团厂，可以选择标证除皮
        if (isOutOfSkin) {
            rl_item22.visibility = View.VISIBLE
        } else {
            rl_item22.visibility = View.INVISIBLE
        }
        rl_item21.isSelected = c1
        rl_item22.isSelected = c2
        setTextColor(c1, text_label21, image_tick_21)
        setTextColor(c2, text_label22, image_tick_22)
    }

    //设置计量类别选中item
    private fun setTextColor(isChecked: Boolean, textView: TextView, imageView: ImageView) {
        when (isChecked) {
            true -> {
                textView.setTextColor(application.resources.getColor(R.color.black))
                imageView.visibility = View.VISIBLE
            }
            false -> {
                textView.setTextColor(application.resources.getColor(R.color.c999999))
                imageView.visibility = View.GONE
            }
        }
    }

    //设置上一步、下一步页面变化
    private fun setDataCausedStep() {
        when (step) {
            1 -> {
                text_top1.setTextColor(application.resources.getColor(R.color.white))
                text_top21.setTextColor(application.resources.getColor(R.color.cfad646))
                text_top21.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view1.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                text_top2.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top22.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top22.setBackgroundResource(R.drawable.bg_gray_cycle)
                view2.setBackgroundColor(application.resources.getColor(R.color.cbababa))
                view3.setBackgroundColor(application.resources.getColor(R.color.cbababa))

                text_top3.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top23.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top23.setBackgroundResource(R.drawable.bg_gray_cycle)
                view4.setBackgroundColor(application.resources.getColor(R.color.cbababa))

                step1.visibility = View.VISIBLE
                step2.visibility = View.GONE
                step3.visibility = View.GONE

                text_btn1.text = "下一步"
                ll_btn2.visibility = View.GONE
            }
            2 -> {

                Log.d("ds", "collectReleaseData-3-" + mReleaseArray)
                //设置合同号相关数据
                if (rl_item11.isSelected) {
                    ll_chooseCompact.visibility = View.GONE
                    adapter.setType(1)
                } else if (rl_item12.isSelected) {
                    adapter.setType(2)
                    ll_chooseCompact.visibility = View.VISIBLE
                }
                adapter.notifyDataSetChanged()

                text_top1.setTextColor(application.resources.getColor(R.color.white))
                text_top21.setTextColor(application.resources.getColor(R.color.white))
                text_top21.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view1.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                text_top2.setTextColor(application.resources.getColor(R.color.white))
                text_top22.setTextColor(application.resources.getColor(R.color.cfad646))
                text_top22.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view2.setBackgroundColor(application.resources.getColor(R.color.cfad646))
                view3.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                text_top3.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top23.setTextColor(application.resources.getColor(R.color.cbababa))
                text_top23.setBackgroundResource(R.drawable.bg_gray_cycle)
                view4.setBackgroundColor(application.resources.getColor(R.color.cbababa))

                step1.visibility = View.GONE
                step2.visibility = View.VISIBLE
                step3.visibility = View.GONE

                text_btn1.text = "上一步"
                ll_btn2.visibility = View.VISIBLE
            }
            3 -> {
                text_top1.setTextColor(application.resources.getColor(R.color.white))
                text_top21.setTextColor(application.resources.getColor(R.color.white))
                text_top21.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view1.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                text_top2.setTextColor(application.resources.getColor(R.color.white))
                text_top22.setTextColor(application.resources.getColor(R.color.cfad646))
                text_top22.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view2.setBackgroundColor(application.resources.getColor(R.color.cfad646))
                view3.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                text_top3.setTextColor(application.resources.getColor(R.color.white))
                text_top23.setTextColor(application.resources.getColor(R.color.cfad646))
                text_top23.setBackgroundResource(R.drawable.bg_yellow_cycle)
                view4.setBackgroundColor(application.resources.getColor(R.color.cfad646))

                step1.visibility = View.GONE
                step2.visibility = View.GONE
                step3.visibility = View.VISIBLE

                ll_bottom.visibility = View.GONE
            }
        }
    }

    //选择物资名称，显示合同号
    override fun showInlineData(data: List<InlineBean>?) {
        when (data) {
            null -> {
                list.clear()
            }
            else -> {
                list.clear()
                list.addAll(data)
            }
        }
    }

    //创建预登记计划成功
    override fun createSucceed() {
        step = 3
        setDataCausedStep()
        //三秒后返回
        Timer().schedule(timerTask {
            returnActivity()
        }, 3 * 1000)
    }

    //创建预登记计划失败
    override fun createFailed(msg: String) {
        toast(msg)
    }
}
